/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

using System;
using Orm;
using System.Collections;
using NHibernate;

namespace petshop {
	/// <summary>
	/// ORM-Persistable Class
	/// </summary>
	public class StaffFactory {
		public static global::petshop.Staff LoadStaffByORMID(int ID) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return LoadStaffByORMID(session,ID);
		}
		
		public static global::petshop.Staff LoadStaffByORMID(PersistentSession session,int ID) {
			return (global::petshop.Staff) session.Load(typeof(global::petshop.Staff), (Int32)ID);
		}
		
		public static global::petshop.Staff[] ListStaffByQuery(string condition, string orderBy) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return ListStaffByQuery(session, condition, orderBy);
		}
		
		public static global::petshop.Staff[] ListStaffByQuery(PersistentSession session, string condition, string orderBy) {
			global::System.Text.StringBuilder sb = new global::System.Text.StringBuilder("From petshop.Staff as Staff");
			if (condition != null) {
				sb.Append(" Where ");
				sb.Append(condition);
			}
			if (orderBy != null) {
				sb.Append(" Order By ");
				sb.Append(orderBy);
			}
			IQuery query = session.CreateQuery(sb.ToString());
			try {
				IList list = query.List();
				global::petshop.Staff[] result = new global::petshop.Staff[list.Count];
				list.CopyTo(result, 0);
				return result;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public static global::petshop.Staff LoadStaffByQuery(string condition, string orderBy) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return LoadStaffByQuery(session, condition, orderBy);
		}
		
		public static global::petshop.Staff LoadStaffByQuery(PersistentSession session, string condition, string orderBy) {
			global::petshop.Staff[] staffs = ListStaffByQuery(session, condition, orderBy);
			if (staffs != null && staffs.Length > 0)
				return staffs[0];
			else
				return null;
		}
		
		public static global::System.Collections.IEnumerable IterateStaffByQuery(string condition, string orderBy) {
			PersistentSession session = global::petshop.PetShopPersistentManager.Instance().GetSession();
			return IterateStaffByQuery(session, condition, orderBy);
		}
		
		public static global::System.Collections.IEnumerable IterateStaffByQuery(PersistentSession session, string condition, string orderBy) {
			global::System.Text.StringBuilder sb = new global::System.Text.StringBuilder("From petshop.Staff as Staff");
			if (condition != null) {
				sb.Append(" Where ");
				sb.Append(condition);
			}
			if (orderBy != null) {
				sb.Append(" Order By ");
				sb.Append(orderBy);
			}
			IQuery query = session.CreateQuery(sb.ToString());
			try {
				return query.Enumerable();
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public static Staff CreateStaff() {
			return new global::petshop.Staff();
		}
		
		public Staff LoadStaffByCriteria(StaffCriteria staffCriteria) {
			Staff[] staffs = ListStaffByCriteria(staffCriteria);
			if(staffs == null || staffs.Length == 0) {
				return null;
			}
			return staffs[0];
		}
		
		public Staff[] ListStaffByCriteria(StaffCriteria staffCriteria) {
			return staffCriteria.ListStaff();
		}
	}
	
}
